#!/usr/bin/env python
# coding: utf-8

# In[6]:


from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import StandardScaler # 对数据归一化
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model #加载线性模型
from sklearn import preprocessing


# load data
digits = load_digits()
 
digits_X = digits.data   ##获得数据集中的输入
digits_y = digits.target ##获得数据集中的输出，即标签(也就是类别)
### test_size:测试数据大小
X_train,X_test,y_train,y_test = train_test_split(digits_X, digits_y, test_size = 0.1)


##加载逻辑回归模型，选择随机平均梯度下降，最大迭代次数选择5000
model_LR_mult=linear_model.LogisticRegression(solver='sag',max_iter=5000,random_state=42,multi_class='ovr')
##将训练数据传入开始训练
model_LR_mult.fit(X_train,y_train)

X_test_scale=preprocessing.StandardScaler().fit_transform(X_test)
print(model_LR_mult.score(X_test_scale,y_test))
y_pred = model_LR_mult.predict(X_test_scale)


# In[ ]:




